/**
 * Created by user on 2017/5/11.
 */
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Random;
import java.text.NumberFormat;
public class FourArithmetic {
    public static void main(String[] args) throws IOException {
        BufferedWriter bw = new BufferedWriter(new FileWriter("LX.txt"));
        ArrayList<String> list = new ArrayList<String>();
        Scanner scan = new Scanner(System.in);
        System.out.print("输入四则运算题目的数量: ");
        int num = scan.nextInt();
        System.out.print("输入包含运算符的数量：");
        int num2 = scan.nextInt();
        long startTime = System.currentTimeMillis();//获取当前时间
        int right = 0;
        for (int i = 0; i < num; i++) {
            Random mod = new Random();
            //  int type = mod.nextInt(12);
            System.out.println("题目" + (i + 1) + ":");
            list.add("题目" + (i + 1) + ":");

            if (num2 == 1) {
                int s1 = mod.nextInt(5) + 1;


                //第一种题型，两个数的加法
                if (s1 == 1) {
                    int a1, b1;
                    int result1;

                    a1 = mod.nextInt(10) + 1;
                    b1 = mod.nextInt(10) + 1;
                    list.add(a1 + "+" + b1 + "=");
                    System.out.println(a1 + "+" + b1 + "=");
        //            result1 = scan.nextInt();
            //        int answer1 = a1 + b1;
           //         if (answer1 == result1) {
           //             System.out.println("正确!");
           //             System.out.println(" ");
            //            right++;
            //        } else if (answer1 != result1) {
            //            System.out.println("错误,正确答案为" + answer1);
            //            System.out.println(" ");
                //    }
                }


                //第二种题型，两个数的减法
                if (s1 == 2) {
                    int a2, b2;
                    int result2;

                    a2 = mod.nextInt(10) + 1;
                    b2 = mod.nextInt(10) + 1;
                    System.out.println(a2 + "-" + b2 + "=");
                    list.add(a2 + "-" + b2 + "=");
        //            result2 = scan.nextInt();
             //       int answer2 = a2 - b2;
             //       if (answer2 == result2) {
              //          System.out.println("正确!");
             //           System.out.println(" ");
              //          right++;
           //         } else if (answer2 != result2) {
            //            System.out.println("错误,正确答案为" + answer2);
             //           System.out.println(" ");
            //        }
                }


                //第三种题型，两个数的乘法
                if (s1 == 3) {
                    int a3, b3;
                    int result3;

                    a3 = mod.nextInt(10) + 1;
                    b3 = mod.nextInt(10) + 1;
                    System.out.println(a3 + "×" + b3 + "=");
                    list.add(a3 + "×" + b3 + "=");
             //       result3 = scan.nextInt();
             //       int answer3 = a3 * b3;
             //       if (answer3 == result3) {
             //           System.out.println("正确!");
             //           System.out.println(" ");
              //          right++;
              //      } else if (answer3 != result3) {
              //          System.out.println("错误,正确答案为" + answer3);
              //          System.out.println(" ");
             //       }
                }


                //第八种题型，两个真分数的加法
                if (s1 == 4) {
                    int a8, b8, c8, d8;
                    a8 = mod.nextInt(10) + 1;
                    b8 = mod.nextInt(10) + 1;
                    c8 = mod.nextInt(10) + 1;
                    d8 = mod.nextInt(10) + 1;
                    Fraction f1 = new Fraction(a8, b8);
                    Fraction f2 = new Fraction(c8, d8);
                    System.out.println(a8 + "/" + b8 + "+" + c8 + "/" + d8 + "=");
            //        String result8 = scan.nextLine();  //无效代码，鸡肋
           //         String result888 = scan.nextLine();
                    list.add(a8 + "/" + b8 + "+" + c8 + "/" + d8 + "=");
                    Fraction answer8 = f1.add(f2);
                    String answer88 = String.valueOf(answer8);
          //          if (answer88.equals(result888)) {
         //               System.out.println("正确!");
          //              System.out.println(" ");
            //            right++;
           //         }else if (answer88 != result888) {
            //            System.out.println("错误,正确答案为" + answer88);
            //            System.out.println(" ");
           //         }
                }
                //第九种题型，两个真分数的减法
                if (s1 == 5) {
                    int a9, b9, c9, d9;
                    a9 = mod.nextInt(10) + 1;
                    b9 = mod.nextInt(10) + 1;
                    c9 = mod.nextInt(10) + 1;
                    d9 = mod.nextInt(10) + 1;
                    Fraction f3 = new Fraction(a9, b9);
                    Fraction f4 = new Fraction(c9, d9);
                    System.out.println(a9 + "/" + b9 + "-" + c9 + "/" + d9 + "=");
                    list.add(a9 + "/" + b9 + "-" + c9 + "/" + d9 + "=");
           //         String result9 = scan.nextLine();
           //         String result999 = scan.nextLine();

                    Fraction answer9 = f3.minus(f4);
              //      String answer99 = String.valueOf(answer9);
            //        if (answer99.equals(result999)) {
            //            System.out.println("正确!");
           //             System.out.println(" ");
           //             right++;
           //         } else if (answer99 != result999) {
          //              System.out.println("错误,正确答案为" + answer99);
           //             System.out.println(" ");
            //        }
                }


                //第十一种题型，两个真分数的除法
                if (s1 == 6) {
                    int a11, b11, c11, d11, e11, f11;
                    a11 = mod.nextInt(10) + 1;
                    b11 = mod.nextInt(10) + 1;
                    c11 = mod.nextInt(10) + 1;
                    d11 = mod.nextInt(10) + 1;
                    Fraction f5 = new Fraction(a11, b11);
                    Fraction f6 = new Fraction(c11, d11);
                    System.out.println(a11 + "/" + b11 + "÷" + c11 + "/" + d11 + "=");
                    list.add(a11 + "/" + b11 + "÷" + c11 + "/" + d11 + "=");
           //         String result10 = scan.nextLine();
           //         String result999 = scan.nextLine();
                    Fraction answer1 = f5.divide(f6);
          //          String answer99 = String.valueOf(answer1);
           //         if (answer99.equals(result999)) {
          //              System.out.println("正确!");
          //              System.out.println(" ");
          //              right++;
          //          } else if (answer99 != result999) {
          //              System.out.println("错误,正确答案为" + answer99);
          //              System.out.println(" ");
           //         }
                }

            }

            if (num2 == 2) {

                int s2 = mod.nextInt(5) + 1;


                //第四种题型，三个数的加法和乘法
                if (s2 == 1) {
                    int a4, b4, c4;
                    int result4;
                    a4 = mod.nextInt(10) + 1;
                    b4 = mod.nextInt(10) + 1;
                    c4 = mod.nextInt(10) + 1;
                    System.out.println(a4 + "＋" + b4 + "×" + c4 + "=");
           //         result4 = scan.nextInt();
                    list.add(a4 + "＋" + b4 + "×" + c4 + "=");
         //           int answer4 = b4 * c4 + a4;
        //            if (answer4 == result4) {
         //               System.out.println("正确!");
          //              System.out.println(" ");
           //             right++;
          //          } else if (answer4 != result4) {
           //             System.out.println("错误,正确答案为" + answer4);
           //             System.out.println(" ");
          //          }
                }
                //第五种题型，三个数的加法和减法
                if (s2 == 2) {
                    int a5, b5, c5;
                    int result5;
                    a5 = mod.nextInt(10) + 1;
                    b5 = mod.nextInt(10) + 1;
                    c5 = mod.nextInt(10) + 1;
                    System.out.println(a5 + "-" + b5 + "+" + c5 + "=");
           //         result5 = scan.nextInt();
                    list.add(a5 + "-" + b5 + "+" + c5 + "=");
          //          int answer5 = a5 - b5 + c5;
            //        if (answer5 == result5) {
            //            System.out.println("正确!");
          //              System.out.println(" ");
          //              right++;
          //          } else if (answer5 != result5) {
          //              System.out.println("错误,正确答案为" + answer5);
          //              System.out.println(" ");
          //          }
                }

                //第六种题型，三个数的加法和乘法，带括号
                if (s2 == 3) {
                    int a6, b6, c6;
                    int result6;
                    a6 = mod.nextInt(10) + 1;
                    b6 = mod.nextInt(10) + 1;
                    c6 = mod.nextInt(10) + 1;
                    System.out.println("(" + a6 + "+" + b6 + ")×" + c6 + "=");
           //         result6 = scan.nextInt();
                    list.add("(" + a6 + "+" + b6 + ")×" + c6 + "=");
         //           int answer6 = (a6 + b6) * c6;
         //           if (answer6 == result6) {
         //               System.out.println("正确!");
         //               System.out.println(" ");
         //               right++;
         //           } else if (answer6 != result6) {
         //               System.out.println("错误,正确答案为" + answer6);
         //               System.out.println(" ");
         //           }
                }

                //第七种题型，三个数的减法和乘法，带括号
                if (s2 == 4) {
                    int a7, b7, c7;
                    int result7;
                    a7 = mod.nextInt(10) + 1;
                    b7 = mod.nextInt(10) + 1;
                    c7 = mod.nextInt(10) + 1;
                    System.out.println(a7 + "×" + "(" + b7 + "-" + c7 + ")=");
          //          result7 = scan.nextInt();
                    list.add(a7 + "×" + "(" + b7 + "-" + c7 + ")=");
      //              int answer7 = a7 * (b7 - c7);
      //              if (answer7 == result7) {
      //                  System.out.println("正确!");
      //                  System.out.println(" ");
      //                  right++;
       //             } else if (answer7 != result7) {
      //                  System.out.println("错误,正确答案为" + answer7);
       //                 System.out.println(" ");
          //          }

                }


                //第十种题型，三个真分数的加法和乘法
                if (s2 == 5) {
                    int a10, b10, c10, d10, e10, f10;
                    a10 = mod.nextInt(10) + 1;
                    b10 = mod.nextInt(10) + 1;
                    c10 = mod.nextInt(10) + 1;
                    d10 = mod.nextInt(10) + 1;
                    e10 = mod.nextInt(10) + 1;
                    f10 = mod.nextInt(10) + 1;
                    Fraction f7 = new Fraction(a10, b10);
                    Fraction f8 = new Fraction(c10, d10);
                    Fraction f9 = new Fraction(e10, f10);
                    System.out.println(a10 + "/" + b10 + "+" + c10 + "/" + d10 + "×" + e10 + "/" + f10 + "=");
       //             String result10 = scan.nextLine();
                    list.add(a10 + "/" + b10 + "+" + c10 + "/" + d10 + "×" + e10 + "/" + f10 + "=");
         //           String result999 = scan.nextLine();
                    Fraction answer = f8.multiply(f9);
                    Fraction answer1 = f7.add(answer);
         //           String answer99 = String.valueOf(answer1);
         //           if (answer99.equals(result999)) {
         //               System.out.println("正确!");
         //               System.out.println(" ");
         //               right++;
          //          } else if (answer99 != result999) {
          //              System.out.println("错误,正确答案为" + answer99);
         //               System.out.println(" ");
         //           }
                }


                //第十二种题型，三个真分数的减法和乘法
                if (s2 == 6) {
                    int a12, b12, c12, d12, e12, f120;
                    a12 = mod.nextInt(10) + 1;
                    b12 = mod.nextInt(10) + 1;
                    c12 = mod.nextInt(10) + 1;
                    d12 = mod.nextInt(10) + 1;
                    e12 = mod.nextInt(10) + 1;
                    f120 = mod.nextInt(10) + 1;
                    Fraction f10 = new Fraction(a12, b12);
                    Fraction f11 = new Fraction(c12, d12);
                    Fraction f12 = new Fraction(e12, f120);
                    System.out.println("(" + a12 + "/" + b12 + "-" + c12 + "/" + d12 + ")×" + e12 + "/" + f120 + "=");
         //           String result10 = scan.nextLine();
                    list.add("(" + a12 + "/" + b12 + "-" + c12 + "/" + d12 + ")×" + e12 + "/" + f120 + "=");
                    String result999 = scan.nextLine();
                    Fraction answer = f10.minus(f11);
                    Fraction answer1 = f12.multiply(answer);
         //           String answer99 = String.valueOf(answer1);
          //          if (answer99.equals(result999)) {
         //               System.out.println("正确!");
         //               System.out.println(" ");
          //              right++;
        //            } else if (answer99 != result999) {
          //              System.out.println("错误,正确答案为" + answer99);
          //              System.out.println(" ");
         //           }
                }

            }
        }

            double rate = (double) right / num;
            NumberFormat fmt = NumberFormat.getPercentInstance();
            System.out.println("完成" + num + "道题，正确率为" + fmt.format(rate));
            long endTime = System.currentTimeMillis();
        System.out.println("Generation cost："+(endTime-startTime)+"ms");
        list.add("Generation cost："+(endTime-startTime)+"ms");
            for (String ai : list) {
                bw.write(ai);
                bw.newLine();
            }
            bw.close();

        }

}
